package org.stu.action;

import java.util.List;
import java.util.Map;

import org.stu.action.base.BaseAction;
import org.stu.dto.*;
import org.stu.util.NewPager;
import org.stu.util.NewPagerService;

import com.opensymphony.xwork2.ActionContext;

public class ShowMainPageAction extends BaseAction {
	private List expenseRecordsList;
	private NewPagerService pagerService;
	private String currentPage;
	private String pagerMethod;
	private String totalPage;

	public String execute() throws Exception {
		Map session = ActionContext.getContext().getSession();
		Integer userId;
		
		if (session.get("userId") == null) {
			return "timeout";
		} else {
			userId = (Integer) session.get("userId");
		}
		int totalRow = expenseManager.getExpenseRecordTotalRows();
		pagerService = new NewPagerService();

		NewPager pager = pagerService.getPager(currentPage, pagerMethod,
				totalRow);
		expenseRecordsList = expenseManager.getExpenseRecordRows(pager.getPageSize(),
				pager.getStartRow(), userId);

		pager=pagerService.getPager(expenseRecordsList.size());
		this.setTotalPage(Integer.toString(pager.getTotalPages()));
		this.setCurrentPage(Integer.toString(pager.getCurrentPage()));
		return SUCCESS;

	}

	public List getExpenseRecordsList() {
		return expenseRecordsList;
	}

	public void setExpenseRecordsList(List expenseRecordsList) {
		this.expenseRecordsList = expenseRecordsList;
	}

	public NewPagerService getPagerService() {
		return pagerService;
	}

	public void setPagerService(NewPagerService pagerService) {
		this.pagerService = pagerService;
	}

	public String getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(String currentPage) {
		this.currentPage = currentPage;
	}

	public String getPagerMethod() {
		return pagerMethod;
	}

	public void setPagerMethod(String pagerMethod) {
		this.pagerMethod = pagerMethod;
	}

	public String getTotalPage() {
		return totalPage;
	}

	public void setTotalPage(String totalPage) {
		this.totalPage = totalPage;
	}

}
